﻿using System;
using Aquiles;

using CIP4.Common;

namespace CIP4.DataProvider.Cassandra
{
    public class Logger : ILogger
    {
        private const string Messageformat = "{0} - [{1}] - [{2}][{3}] {4} - {5}";

        #region ILogger Members

        public void Fatal(string className, object message)
        {
            Fatal(className, message, null);
        }

        public void Fatal(string className, object message, Exception exception)
        {
            Globals.DefaultLogger(MajorEnum.Error, MinorEnum.GenericProvider, Messageformat, 
                new object[] {DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, "fatal", className, 
                (message != null) ? message.ToString() : String.Empty, 
                (exception != null) ? exception.ToString() : String.Empty});
        }

        public void Error(string className, object message)
        {
            Error(className, message, null);
        }

        public void Error(string className, object message, Exception exception)
        {
            Globals.DefaultLogger(MajorEnum.Warning, MinorEnum.GenericProvider, Messageformat, 
                new object[] {DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, "warning", className, 
                (message != null) ? message.ToString() : String.Empty, 
                (exception != null) ? exception.ToString() : String.Empty});
        }

        public void Warn(string className, object message)
        {
            Warn(className, message, null);
        }

        public void Warn(string className, object message, Exception exception)
        {
            Globals.DefaultLogger(MajorEnum.Warning, MinorEnum.GenericProvider, Messageformat, 
                new object[] {DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, "warning", className, 
                (message != null) ? message.ToString() : String.Empty, 
                (exception != null) ? exception.ToString() : String.Empty});
        }

        public void Info(string className, object message)
        {
            Info(className, message, null);
        }

        public void Info(string className, object message, Exception exception)
        {
            Globals.DefaultLogger(MajorEnum.Trace, MinorEnum.GenericProvider, Messageformat, 
                new object[] {DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, "info", className, 
                (message != null) ? message.ToString() : String.Empty, 
                (exception != null) ? exception.ToString() : String.Empty});
        }

        public void Trace(string className, object message)
        {
            Info(className, message);
        }

        public void Trace(string className, object message, Exception exception)
        {
            Globals.DefaultLogger(MajorEnum.Trace, MinorEnum.GenericProvider, Messageformat, 
                new object[] {DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, "trace", className, 
                (message != null) ? message.ToString() : String.Empty, 
                (exception != null) ? exception.ToString() : String.Empty});
        }

        public void Debug(string className, object message)
        {
            Debug(className, message, null);
        }

        public void Debug(string className, object message, Exception exception)
        {
            Globals.DefaultLogger(MajorEnum.Noise, MinorEnum.GenericProvider, Messageformat, 
                new object[] {DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, "debug", className, 
                (message != null) ? message.ToString() : String.Empty, 
                (exception != null) ? exception.ToString() : String.Empty});
        }

        #endregion
    }
}
